Repository navigation
Prevent unenrollment on order removal when student has another active order - #3483
Open
noruzzamans wants to merge 2 commits into
Open
noruzzamans wants to merge 2 commits into
noruzzamans wants to merge 2 commits into
Conversation
noruzzamans
marked this pull request as ready for review
November 13, 2026 17:14
Contributor
|
@noruzzamans Thanks for the PR! Is this something you've observed on an actual site without editing the database? Since you can't purchase the same product multiple times, it's not something we've actually be able to reproduce. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When an order is trashed or permanently deleted,
LLMS_Controller_Orders::error_order()andLLMS_Controller_Orders::on_delete_order()attempt to unenroll the student or delete their enrollment scoped to the specific order trigger (order_<id>).Previously, if an enrollment had no stored
_enrollment_trigger(for example, legacy enrollments, or enrollments imported or created without a trigger), or if an older order was being trashed while a newer active order still existed,LLMS_Student::unenroll()andLLMS_Student::delete_enrollment()fell back to unenrollment/deletion regardless of other existing orders. Consequently, moving an unrelated failed order to the trash or deleting it would cancel or remove enrollment for a student who still had an active or completed order backing the product.This update:
LLMS_Student::get_active_order_for_product()to determine whether the student has another active (llms-active) or completed (llms-completed) order for the given product, with optional exclusion of the order currently being removed.LLMS_Student::set_enrollment_trigger()as a helper to persist a new enrollment trigger.LLMS_Student::unenroll()andLLMS_Student::delete_enrollment(), before proceeding with unenrollment or deletion, checks if another active or completed order exists for the student and product. If one is found, unenrollment or deletion is skipped and_enrollment_triggeris updated to point to that active order.Fixes #3464
How has this been tested?
test_error_order_preserves_enrollment_when_active_order_exists()inclass-llms-test-controller-orders.phpto verify that trashing an order does not unenroll a student who has another active order for the product.test_on_delete_order_preserves_enrollment_when_active_order_exists()inclass-llms-test-controller-orders.phpto verify that permanently deleting an order preserves enrollment when another active order exists.test_error_order_matching_trigger_preserves_enrollment_when_active_order_exists()inclass-llms-test-controller-orders.phpto verify the edge case where an older order matching the trigger is trashed while a newer active order exists.class-llms-test-model-llms-student.phpcoveringget_active_order_for_product(),set_enrollment_trigger(), and unenrollment/deletion guards when trigger is missing.phpcs.xml(0 errors, 0 warnings on new code).Screenshots
N/A
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
[x] This PR requires and contains at least one changelog file.
[x] My code has been tested.
[x] My code passes all existing automated tests.
[x] My code follows the LifterLMS Coding & Documentation Standards.